package com.ykt.service;

import com.jfinal.aop.Enhancer;
import com.ykt.cache.Ys7Cache;
import com.ykt.common.thirdapi.ys7.Ys7ApiHelper;
import com.ykt.exception.BusinessException;
import com.ykt.vo.ResultStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 萤石云视频api操作，本类一部分方法将移入CMS中
 * @author long.hua
 * @version 1.0.0
 * @since 2015-12-22 00:27
 */
public class Ys7Service {
    private static final Logger LOGGER = LoggerFactory.getLogger(Ys7Service.class);


    private Ys7Cache ys7Cache = Enhancer.enhance(Ys7Cache.class.getName(), Ys7Cache.class);
    private Ys7ApiHelper ys7ApiHelper = Enhancer.enhance(Ys7ApiHelper.class.getName(), Ys7ApiHelper.class);


    public String getAccessToken(){
        String token = ys7Cache.getAccessToken();
        if(token == null){

            token = ys7ApiHelper.getAccessToken();
            if(token != null){
                ys7Cache.saveAccessToken(token);
            } else {
                throw new BusinessException(ResultStatus.CALL_API_ERROR, ResultStatus.CALL_API_ERROR_MSG);
            }
        }

        return token;
    }

    /** 获取YS7服务器时间 */
    public long getServerTime() {
        return ys7ApiHelper.getServerTime();
    }

}

